package main

import (
	"fmt"
	"html/template"
	"os"
)
import s "strings"

var p = fmt.Println

func fmtstringMain() {
	p("contains ", s.Contains("test", "es"))
	p("count ", s.Count("test", "es"))
	p("HasPrefix ", s.HasPrefix("test", "es"))
	p("HasSuffix ", s.HasSuffix("test", "es"))
	p("Index ", s.Index("test", "es"))
	p("Join", s.Join([]string{"a", "b"}, "+++++"))
	p("Replace", s.Replace("ksodkkkk", "k", "dddd", -1))
	p("ToLower", s.ToLower("TEST"))
	p("ToUpper", s.ToUpper("TESTaaaaaas"))
	p("Split", s.Split("T-E-S-T", "-"))

	var s = pois{1, 23}
	fmt.Printf("struct1 : %v\n", s)
	fmt.Printf("struct2 : %#v\n", s)
	fmt.Printf("struct2 : %+v\n", s)
	fmt.Printf("struct2 : %T\n", s)
	fmt.Printf("struct2 : %v\n", true)
	fmt.Printf("float2: %e\n", 123400000.0)
	fmt.Printf("float3: %E\n", 123400000.0)
	fmt.Printf("width1: |%6d|%6d|\n", 12, 345)
	ostemp()
}

type pois struct {
	x, y int32
}

func ostemp() {
	var t = template.New("t1")
	t, err := t.Parse("Value is {{.}}\n")
	if err != nil {
		panic(err)
	}
	t = template.Must(t.Parse("Value :{{.}}\n"))
	t.Execute(os.Stdout, "some text")
	t.Execute(os.Stdout, 5)
	t.Execute(os.Stdout, []string{
		"Go",
		"Rust",
		"C++",
		"C#",
	})
	Create := func(name, t string) *template.Template {
		return template.Must(template.New(name).Parse(t))
	}
	t2 := Create("t2", "Name: {{.Name}}\n")
	t2.Execute(os.Stdout, struct {
		Name string
	}{"Jane Doe"})
	t2.Execute(os.Stdout, map[string]string{
		"Name": "Mickey Mouse",
	})

	t3 := Create("t3",
		"{{if . -}} yes {{else -}} no {{end}}\n")
	t3.Execute(os.Stdout, "not empty")
	t3.Execute(os.Stdout, "")
	t4 := Create("t4",
		"Range: {{range .}}{{.}} {{end}}\n")
	t4.Execute(os.Stdout,
		[]string{
			"Go",
			"Rust",
			"C++",
			"C#",
		})
}
